############## 
############## 
############## Models
remove(list = ls())

base::library(conflicted)
base::library(tidyverse)
conflict_prefer("filter","dplyr")
base::library(ggplot2)
base::library(dplyr)
base::library(here)
conflict_prefer("here", "here")
base::library(systemfit)
#base::library(sf)
#base::library(sp)
#base::library(spdep)
#base::library(spatialreg)
#base::library(rgdal)
#base::library(utils)
#base::library(geodist)
base::library(stargazer)
#base::library(texreg)
base::library(DataCombine)
#base::library(reshape2)

data20 <- read.csv(here("Data", "AME_Bootstrap_CountyLevel_20Shock.RData"))
data40 <- read.csv(here("Data", "AME_Bootstrap_CountyLevel_40Shock.RData"))
data60 <- read.csv(here("Data", "AME_Bootstrap_CountyLevel_60Shock.RData"))
data80 <- read.csv(here("Data", "AME_Bootstrap_CountyLevel_80Shock.RData"))
data100 <- read.csv(here("Data", "AME_Bootstrap_CountyLevel_100Shock.RData"))
data120 <- read.csv(here("Data", "AME_Bootstrap_CountyLevel_120Shock.RData"))


data20 <- data20 %>% 
  mutate(shock = 20)
data40 <- data40 %>% 
  mutate(shock = 40)
data60 <- data60 %>% 
  mutate(shock = 60)
data80 <- data80 %>% 
  mutate(shock = 80)
data100 <- data100 %>% 
  mutate(shock = 100)
data120 <- data120 %>% 
  mutate(shock = 120)

plot_data <- rbind(data20, data40, data60, data80, data100, data120)
glimpse(plot_data)


fig_sim <- plot_data %>% 
  mutate(party = factor(party, levels = c("Republican",
                                          "Democratic",
                                          "Abstention"),
                        labels = c("Republican",
                                   "Democratic",
                                   "Abstention"))) %>% 
  mutate(shock = factor(shock, levels = c(20, 40, 60, 80, 100, 120),
                        labels = c(20, 40, 60, 80, 100, 120))) %>% 
  ggplot(aes(shape = shock)) +
  geom_hline(yintercept = 0, colour = "gray27",  lty = 2, linewidth = 0.75) +
  geom_pointrange(aes(x = party, y = mean, ymin = lb,
                      ymax = ub), colour = "black", fill = "black",
                  lwd = 0.6, position = position_dodge(width = .5)) + 
  scale_shape_manual(name = "Shock in Death Rates:",
                     values = c(22, 21, 24, 25, 3 , 4)) +
  scale_y_continuous(breaks = c(-0.02, -0.01, 0, 0.01, 0.02, 0.03), lim = c(-0.024, 0.0375)) +
  theme_bw() + #ylim(-0.025, 0.02) +
  labs(y = "Difference in Predicted Share of Voters") +
  xlab(NULL) +
  theme(axis.text.x = element_text(size = 13#, 
                                   #hjust = 1, 
                                   #angle = 15
  ),
  axis.text.y = element_text(size = 12),
  axis.title.y = element_text(size = 12),
  legend.text = element_text(size = 13),
  legend.title = element_text(size = 13),
  legend.position = "bottom",
  legend.direction = "horizontal",
  title = element_text(size = 14)) #+
#ggtitle("Change in Percentage of Voters after 1-SD Shock in House Price")
fig_sim



